package com.jsean;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DuckDBDemo {
    public static void main(String[] args) {
        try {
            // 1. 创建表
            DuckDBUtil.createTable("users", "id INTEGER PRIMARY KEY, name VARCHAR, age INTEGER");
            
            // 2. 批量插入数据
            List<Map<String, Object>> users = new ArrayList<>();
            for (int i = 1; i <= 5; i++) {
                Map<String, Object> user = new HashMap<>();
                user.put("id", i);
                user.put("name", "User" + i);
                user.put("age", 20 + i);
                users.add(user);
            }
            DuckDBUtil.batchInsert("users", users);
            
            // 3. 查询数据
            List<Map<String, Object>> result = DuckDBUtil.executeQuery("SELECT * FROM users WHERE age > ?", 22);
            System.out.println("查询结果:");
            result.forEach(System.out::println);
            
            // 4. 更新数据
            int updated = DuckDBUtil.executeUpdate("UPDATE users SET age = ? WHERE id = ?", 30, 1);
            System.out.println("更新了 " + updated + " 条记录");
            
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}